javascript"."符号怎么样转义?

来源:百度知道 编辑:UC知道 时间:2024/06/19 11:26:09
function register() {
alert(document.forms[0].user.username.value);
}

<html:form action="register.do?operate=register">
<b>用户名:</b> <html:text property="user.username" size="20"/>
<html:button value="注  册" property="registerBtn" onclick="register()"/>
</html:form>
怎么取这个值user.username~
alert(document.forms[0].user["username.value"]);
这样写取不到值的

alert(document.forms[0]['user.username'].value);
这个学名叫关联数组,虽然是对象类型的
在双/单引号里可以包括各种字符(未转义的换行符和双/单引号)

alert(document.forms[0].user["username.value"]);

alert(document.forms[0]["user.username"].value);

document.forms和document['forms']是相同的意思,只是写法不同而已